package p8;

import java.util.Comparator;

/**
 * @author krystal
 * @date 2022/11/12 14:07
 */
class Student /*implements Comparable<Student>*/{
    public String name;
    public int age;
    public int score;

    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

//    @Override
//    public int compareTo(Student o) {
//        return this.age-o.age;
//    }

}

class AgeComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }
}

class ScoreComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.score-o2.score;
    }
}

public class Demo4 {
    public static void main(String[] args) {
        Student s1=new Student("11",16,98);
        Student s2=new Student("22",19,34);
        AgeComparator ageComparator=new AgeComparator();
        int ret=ageComparator.compare(s1,s2);
        System.out.println(ret);
        ScoreComparator scoreComparator=new ScoreComparator();
        int ret1=scoreComparator.compare(s1,s2);
        System.out.println(ret1);
    }

//    public static void main1(String[] args) {
//        Student s1=new Student("11",16,98);
//        Student s2=new Student("22",19,34);
//        if (s1.compareTo(s2)<0){
//            System.out.println("s1小于s2");
//        }else if (s1.compareTo(s2)==0){
//            System.out.println("s1等于s2");
//        }else {
//            System.out.println("s1大于s2");
//        }
//    }
}
